package sumOfDigitsBeforeLetters;

import java.util.Scanner;

public class SumOfDigitsBeforeLetters {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入多行字符串（输入exit退出程序）：");

        int totalSum = 0;

        while (true) {
            String input = scanner.nextLine();
            if ("exit".equalsIgnoreCase(input)) {
                System.out.println("程序已退出。");
                System.out.println("所有行的数字和为：" + totalSum);
                break;
            }

            int sum = 0;
            for (int i = 0; i < input.length() - 1; i++) {
                char currentChar = input.charAt(i);
                char nextChar = input.charAt(i + 1);


                if (Character.isDigit(currentChar) && (nextChar == 'a' || nextChar == 'b' || nextChar == 'c')) {
                    sum += Character.getNumericValue(currentChar);
                }
            }
            totalSum += sum;
            System.out.println("当前行的数字和为：" + sum);
        }

        scanner.close();
    }
}
